﻿import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'ringSetting_logic.dart';

/// 戒指设置页面
class RingView extends GetView<RingSettingLogic> {
  const RingView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor:  Colors.black,
      appBar: AppBar(
        backgroundColor: const Color(0xFF282528),
        elevation: 0,
        leading: GestureDetector(
          onTap: () => Get.back(),
          child: const Icon(
            Icons.arrow_back_ios,
            color: Colors.white,
            size: 20,
          ),
        ),
        title: const Text(
          '戒指设置',
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.w500,
          ),
        ),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        padding: EdgeInsets.all(24.w),
        child: Column(
          children: [
            Container(
              decoration: BoxDecoration(
                color: const Color(0xFF282528),
                borderRadius: BorderRadius.circular(28.r),
              ),
              child: Column(
                children: [
                  Obx(() => _buildListItem(
                        '单位格式',
                        controller.unitFormat.value,
                        () => controller.selectUnitFormat(),
                      )),
                  _buildDivider(),
                  Obx(() => _buildListItem(
                        '白天心率/HRV测量间隔',
                        controller.intervalTime.value > 0
                            ? '${controller.intervalTime.value}分钟'
                            : '',
                        () => controller.selectIntervalTime(),
                      )),
                  _buildDivider(),
                  Obx(() => _buildListItem(
                        '血氧饱和度',
                        controller.oxygenSaturation.value > 0
                            ? '${controller.oxygenSaturation.value}小时'
                            : '',
                        () => controller.selectOxygenSaturation(),
                      )),
                  _buildDivider(),
                  Obx(() => _buildListItem(
                        '压力',
                        controller.pressure.value > 0
                            ? '${controller.pressure.value}小时'
                            : '',
                        () => controller.selectPressure(),
                      )),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildListItem(String title, String value, VoidCallback onTap) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        height: 50.h,
        padding: EdgeInsets.symmetric(horizontal: 20.w),
        child: Row(
          children: [
            Text(
              title,
              style: TextStyle(
                color: Colors.white,
                fontSize: 16.sp,
              ),
            ),
            const Spacer(),
            if (value.isNotEmpty)
              Text(
                value,
                style: TextStyle(
                  color: const Color(0xFF666666),
                  fontSize: 14.sp,
                ),
              ),
            SizedBox(width: 8.w),
            const Icon(
              Icons.arrow_forward_ios,
              color: Color(0xFF666666),
              size: 16,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildDivider() {
    return Divider(
      height: 1,
      thickness: 1,
      color: const Color(0xFF1A1A1A),
      indent: 20.w,
      endIndent: 20.w,
    );
  }
}
